Sharing Data Among Applications
Sharing Data Among Applications
The Edition Manager lets applications share dynamic data at the user's
request. (The Clipboard lets applications share static data.) You build publish
and subscribe capabilities into your application in much the same way that you
build copy and paste into your application.
Using the Edition Manager, you can let a user publish data by selecting a
portion of text, graphics, or other data within a document and choosing Create
Publisher from the Edit menu. When the user performs this action, your
application saves the selected information in a separate file. The information
that is stored in a separate file is referred to as an edition. You can also let a
user subscribe to data in an edition by choosing Subscribe To from the Edit
menu; when the user chooses an edition, your application includes the
information from the edition in the current document. The information in an
edition can be shared by many documents.
A publisher is a portion of a document that is made available to other
documents through an edition. A subscriber is a portion of a document that
receives the information from an edition.
The Figure below shows a document containing a publisher, a file containing
an edition, and a document containing a subscriber. The bottom fish in the
Fishes of the World document is a publisher. The information from this
publisher is made available to other documents through the Illustration
edition. The Aquarium poster document contains a subscriber that gets its
information from the Illustration edition. Note that when a user selects a
publisher or subscriber within a document, your application should display a
border surrounding the publisher or subscriber.
In general, when a user modifies the contents of a publisher and saves the
document, your application should write the new data to the edition. The
Edition Manager then informs all open applications with documents that
subscribe to the edition that the edition contains updated information. These
applications can then automatically update the subscribers in the documents.
For example, in the Figure above, if the user changes the color of the fish in
the Fishes of the World document and then saves the document, the change can
be automatically made in the Illustration edition and the Aquarium poster
document.
A publisher, an edition, and a subscriber
The Figure below shows how a user might create a poster by using
information from other documents. For example, the user could subscribe to
separate editions containing an illustration created by a graphics designer,
text created by a writer, and a headline created by an editor.
Sharing dynamic data with other applications
Your application should save the new information in the edition whenever the
user edits the publisher and saves the document that contains the
publisher-unless the user has indicated that the information should be saved in
the edition on request only. Saving new information in an edition replaces the
previous contents of the edition.
When the information in an edition changes, the Edition Manager informs
your application. Your application should then update any subscribers with the
new information from the edition (unless the user has indicated that updates
should be incorporated on request only).
For example, a user might open a word-processing document called My Stocks
that accesses information from an edition called Stock Report. The Stock
Report edition might be updated twice a day by an on-line database. As the
information in the edition changes, the My Stocks document can receive
automatic updates with the latest information.
You can implement publish and subscribe capabilities in your application by
using the routines provided by the Edition Manager and supporting the
required set of Apple events. See the Edition Manager for sample code that
shows how to add these features to your application.